﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Contact : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["user"] != null)
            {
                this.Log_in1.Visible = false;
                this.Log_out1.Visible = true;
            }
            else
            {
                this.Log_in1.Visible = true;
                this.Log_out1.Visible = false;
            }
        }
        else
        {
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        ProContact pct = new ProContact();
        if (this.txtName.Text.Trim() == "" || this.txtEmail.Text.Trim() == "" || this.txtContent.Text.Trim() == "")
        {
            this.lblError.Text = "Please input full field requires";
            return;
        }

        EnContact ct = new EnContact();
        ct.StrName = this.txtName.Text;
        ct.StrAddress = this.txtAddress.Text;
        ct.StrPhone = this.txtPhone.Text;
        ct.StrEmail = this.txtEmail.Text;
        ct.StrComment = this.txtContent.Text;
        ct.StaStatus.Id = 4;
        Boolean bResult = pct.InsertContact(ct);
        if (bResult == true)
        {
            this.lblError.Text = Constant.MESSAGE_INSERT_SUCCESS;
            String subject = "Bạn vừa nhận được 1 góp ý từ khách hàng";
            String link = "http://" + Request.Url.Authority + "/ReplyContact.aspx";
            ProSendMail psm = new ProSendMail();
            psm.sendmailContact(Constant.EMAIL_ADMIN, subject, link );
            Response.Redirect("Result.aspx?contact=ok");
        }
        else
        {
            this.lblError.Text = Constant.MESSAGE_INSERT_ERROR;
            return;
        }
    }
    
}
